package ACwing.P1BasicAlgorithm.qianzhuihe;

import java.util.Scanner;

/**
 * @Date : 2022/10/23
 * @Description:
 * 1.s[i,j]如何计算？
 * 2.(x1,y1),(x2,y2)这一子矩阵中所有数的和该如何计算？
 *
 * 1.S[i,j]=s[i-1,j]+S[i,j-1]-S[i-1,j-1]+a[i,j]
 *
 * 2.S[x2,y2]-S[x1-1,y2]-S[x2,y1-1]+S[x1-1,y1-1]
 */
public class Pre2D {
    static  final int N=1010;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int q = sc.nextInt();
        int [] [] ar= new int[N][N],s = new int[N][N];
        s[0][0]=0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <=m ; j++) {
                ar[i][j]=sc.nextInt();
                //初始化前缀和数组
                s[i][j]= s[i-1][j]+s[i][j-1]-s[i-1][j-1]+ar[i][j];
            }
        }
        //询问
        while(q--!=0){
            int x1= sc.nextInt();
            int y1= sc.nextInt();
            int x2= sc.nextInt();
            int y2= sc.nextInt();
            System.out.println(s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]);
        }

    }

}
